#include "GDALCPP.h"

namespace OCPP
{
    detail::init_wrapper::init_wrapper() noexcept
    {
        GDALAllRegister();
    }

    detail::Driver::Driver(const String& driver_name) :
        init_library(),
        m_driver(GetGDALDriverManager()->GetDriverByName(driver_name.c_str())) {
        if (!m_driver) {
            throw gdal_error{ String{"unknown driver: '"} + driver_name + "'",
                             OGRERR_NONE,
                             driver_name };
        }
    }

    gdal_error::gdal_error(const String& message,
        OGRErr error,
        const String& driver,
        const String& dataset,
        const String& layer,
        const String& field) :
        std::runtime_error(message),
        m_driver(driver),
        m_dataset(dataset),
        m_layer(layer),
        m_field(field),
        m_error(error) {
    }

    void Dataset::gdal_dataset_deleter::operator()(gdal_dataset_type* ds) {
        GDALClose(ds);
    }
}